home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / drgnsmth.cpt / Dragonsmith 1.1 / Base files / Utilities / TrapUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-10  |  1.8 KB  |  74 lines

  1. /*
  2.     TrapUtils.c
  3.     
  4.     OS and Toolbox trap-related utility functions.  Adapted from code in Inside Macintosh Volume VI, pages 3╨8 to 3╨9
  5.     
  6.     Created    17 Sep 1992    TrapAvailable and its static "herlper" functions
  7.     Modified    
  8.  
  9.     Copyright ⌐ 1992 by Paul M. Hoffman
  10.     Send comments or suggestions to paul.hoffman@um.cc.umich.edu
  11.     
  12.     This source code may be freely used, altered, and distributed in any way as long as:
  13.         1.    It is GIVEN away rather than sold (except as expressly permitted by the author)
  14.         2.    This statement and the above copyright notice are left intact.
  15.     
  16. */
  17.  
  18. #include    "TrapUtils.h"
  19. #include    <Traps.h>
  20.  
  21. static short NumToolboxTraps (void);
  22. static long AA6EAddress (void);
  23. static long UnimplementedTrapAddress (void);
  24. static TrapType GetTrapType (short trapWord);
  25.  
  26. Boolean TrapAvailable (short theTrap)
  27. {
  28.     TrapType        type;
  29.     
  30.     type = GetTrapType (theTrap);
  31.     if (type == ToolTrap) {
  32.         theTrap &= 0x07FF;
  33.         if (theTrap >= NumToolboxTraps ())
  34.             return FALSE;
  35.     }
  36.     return (NGetTrapAddress (theTrap, type) != UnimplementedTrapAddress ());
  37. }
  38.  
  39. static short NumToolboxTraps (void)
  40. {    
  41.     static short    NUM_TBX_TRAPS = -1;        // Initialize NUM_TBX_TRAPS to a nonsensical value
  42.  
  43.     if (NUM_TBX_TRAPS == -1)
  44.         NUM_TBX_TRAPS = ((NGetTrapAddress (_InitGraf, ToolTrap) == AA6EAddress ()) ? 0x0200 : 0x0400);
  45.         
  46.     return NUM_TBX_TRAPS;
  47. }
  48.  
  49. static long AA6EAddress (void)
  50. {
  51.     static long    AA6E_ADDR = -1;            // Initialize _AA6E_ADDR to a nonsensical value
  52.     
  53.     if (AA6E_ADDR == -1)
  54.         AA6E_ADDR = NGetTrapAddress (0xAA6E, ToolTrap);
  55.         
  56.     return AA6E_ADDR;
  57. }
  58.  
  59. static long UnimplementedTrapAddress (void)
  60. {
  61.     static long    UNIMP_TRAP_ADDR = -1;    // // Initialize UNIMP_TRAP_ADDR to a nonsensical value
  62.     
  63.     if (UNIMP_TRAP_ADDR == -1)
  64.         UNIMP_TRAP_ADDR = NGetTrapAddress (_Unimplemented, ToolTrap);
  65.         
  66.     return UNIMP_TRAP_ADDR;
  67. }
  68.  
  69. static TrapType GetTrapType (short trapWord)
  70. {
  71.     return (trapWord & 0x0800) ? ToolTrap : OSTrap;
  72. }
  73.  
  74.